package com.bridge.common.utils;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.bridge.common.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName CalendarDayUtils
 * @Description TODO消息
 * @Author xushufeng
 * @CreateDate 2021/4/11 0011 17:04
 * @Version 1.0
 * @UpdateDate 2021/4/11 0011 17:04
 * @UpdateRemark 更新说明
 */
public class CalendarDayUtils {
    TimePickerView pvTime;
    public static Context context;
    private static CalendarDayUtils calendarTimeUtils = null;
    public static CalendarDayUtils getInstance(Context mcontext) {
        context = mcontext;
        if (calendarTimeUtils == null) {
            synchronized (CalendarDayUtils.class) {
                if (calendarTimeUtils == null) {
                    calendarTimeUtils = new CalendarDayUtils();
                }
            }
        }
        return calendarTimeUtils;
    }
    public TimePickerView setDateTime() {
        //控制时间范围(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
        //因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(2013, 0, 23);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2029, 11, 28);
        //时间选择器
        pvTime = new TimePickerView.Builder(context, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                // 这里回调过来的v,就是show()方法里面所添加的 View 参数，如果show的时候没有添加参数，v则为null
                TextView btn = (TextView) v;
                btn.setText(getTimes(date));
            }
        })//年月日时分秒 的显示与否，不设置则默认全部显示
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("", "", "", "", "", "")
                .isCenterLabel(true)
                .setDividerColor(Color.DKGRAY)
                .setContentSize(18)//字号
                .setDate(selectedDate)
                .setCancelColor(context.getResources().getColor(R.color.color_24c36b))
                .setSubmitColor(context.getResources().getColor(R.color.color_24c36b))
                .setTitleText("请选择出生日期")
                .setTitleSize(16)
                .setTitleColor(context.getResources().getColor(R.color.color_171515))
                .setRangDate(startDate, endDate)
                .setDecorView(null)
                .build();
        return pvTime;

    }

    private String getTimes(Date date) {//年月日时分秒格式
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }
}
